import cv2 as cv
import sys
import os
from python_ai.common.xcommon import *
import matplotlib.pyplot as plt
import numpy as np
import time
import datetime


def empty_callback(x):
    pass


title = 'Drag to get color'
cv.namedWindow(title)
cv.createTrackbar('R', title, 255, 255, empty_callback)
cv.createTrackbar('G', title, 255, 255, empty_callback)
cv.createTrackbar('B', title, 255, 255, empty_callback)
# img = np.ones([240, 320, 3], dtype=np.uint8) * 255
img = np.full([240, 320, 3], 255, dtype=np.uint8)

key_set = set([ord('q'), ord('Q'), 27])
while True:
    k = cv.waitKey(150)
    if k in key_set:
        break

    r = cv.getTrackbarPos('R', title)
    g = cv.getTrackbarPos('G', title)
    b= cv.getTrackbarPos('B', title)
    img[:, :] = [b, g, r]
    cv.imshow(title, img)

cv.destroyAllWindows()
